package edu.yonsei.iwb.smarttv.querygraph;

import com.hp.hpl.jena.graph.Node;
import com.hp.hpl.jena.rdf.model.Resource;
import edu.yonsei.iwb.smarttv.model.NodeType;
import edu.yonsei.iwb.smarttv.model.ResourceNode;
import edu.yonsei.iwb.smarttv.model.measure.WeightModel;
import java.util.*;

/**
 * 사용자 질의를 QueryKeyword 별로 담기 위한 클래스
 * 
 * @author Joo
 */
public class QueryCombination extends Vector<ResourceNode> {
    
    String id;
    double score;
//    Vector<Double> score;
    
    public QueryCombination() {
    }

    public QueryCombination(QueryCombination qc) {
        this.addAll(qc);
    }
    
    public void setid(int i){
        this.id = "QC"+i;
    }
    
    public String getid(){
        return this.id;
    }
    
    public int getSizeOfPropertyType(){
        int result = 0;
        // 마지막에 들어간 프로퍼티 무시
        for (int i = 0; i < this.size()-1; i++) {
            ResourceNode rn = this.get(i);
            if(rn.getType() == NodeType.PROPERTY_TYPE){
                result++;
            }
        }
        return result;
    }

    public Vector<Resource> getAllMappedResource() {
        Vector<Resource> rSet = new Vector<Resource>();
        for (int i = 0; i < this.size(); i++) {
            ResourceNode rn = this.get(i);
            Resource r = rn.getNode();
            if (!rSet.contains(r)) {
                rSet.add(r);
            }
        }
        return rSet;
    }
    
    /**
     * query combination의 score 산출
     * @param wm
     * @return 
     */
    public void setScore(WeightModel wm){        
        this.score = 0.0;        
        for (int j = 0; j < this.size(); j++) {
            ResourceNode rn = this.get(j);
            Resource r = rn.getNode();            
            double w = wm.getUserPreferenceWeight(r);
            this.score += w;
        }        
    }
    
    public double getScore(){
        return this.score;
    }    

    @Override
    public String toString() {
        StringBuffer sb = new StringBuffer();
        sb.append("[");
        for (int i = 0; i < this.size(); i++) {
            sb.append(this.get(i).toString());
            if (i != (this.size() - 1)) {
                sb.append(", ");
            }
        }
        sb.append("]");
        return sb.toString();
    }
}
